//
//  UIButton+Extension.swift
//  WeiBo_test
//
//  Created by 张leslie45 on 16/1/20.
//  Copyright © 2016年 张leslie45. All rights reserved.
//

import UIKit

extension UIButton{
  //指定背景图片 和按钮的图片的构造函数
    convenience init(imageName:String,backImageName:String){
      self.init()
       setImage(UIImage(named: imageName), forState: .Normal)
       setImage(UIImage(named: imageName + "_highlighted"), forState: .Highlighted)
       setBackgroundImage(UIImage(named: backImageName), forState: .Normal)
       setBackgroundImage(UIImage(named: backImageName + "_highlighted"), forState: .Highlighted)
       
        //指定大小 
        sizeToFit()
    }

    convenience init(title:String,fontSize:CGFloat,color:UIColor,backImageName:String?,imageName:String? = nil){
       self.init()
        //设置按钮的文字
        setTitle(title, forState: .Normal)
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
        setTitleColor(color, forState: .Normal)
        
        if backImageName != nil{
            setBackgroundImage(UIImage(named:backImageName!), forState: .Normal)
        }
        if imageName != nil{
            setImage(UIImage(named: imageName!), forState: .Normal)
        }
    }
}